﻿#ifndef BridgeCpp_h__
#define BridgeCpp_h__

#ifdef __cplusplus
extern "C" {
#endif
	typedef int BOOL;
#define TRUE 1
#define FALSE 0
	typedef struct dtNavMesh dtNavMesh;
	typedef struct PathFinder PathFinder;
	typedef struct TempObstaclesNavMesh TempObstaclesNavMesh;

	dtNavMesh* GetNavMesh(char* name);
 	PathFinder* GetFinder(dtNavMesh* navmesh);
 	void ReleaseMap();
	float* FindPath(PathFinder* finder, float sposX, float sposY, float sposZ, float eposX, float eposY, float eposZ, int* count);
	float* CalcNear(PathFinder* finder, float sposX, float sposY, float sposZ, int* count);
	float* CalcRaycast(PathFinder* finder, float sposX, float sposY, float sposZ, float eposX, float eposY, float eposZ, int* count);
	// 释放地图
	void FreeNavMesh(PathFinder* pathfinder);
	// Temp obstacles的接口
	TempObstaclesNavMesh* GetNavMeshTO(char* name);
	void ReleaseMapTO();
	float* FindPathTO(TempObstaclesNavMesh* toNavMesh, float sposX, float sposY, float sposZ, float eposX, float eposY, float eposZ, int* count);
	BOOL FindPathExTO(TempObstaclesNavMesh* toNavMesh, float sposX, float sposY, float sposZ, float eposX, float eposY, float eposZ);
	float* GetPath(TempObstaclesNavMesh* toNavMesh, int* count);
	float* CalcNearTO(TempObstaclesNavMesh* toNavMesh, float sposX, float sposY, float sposZ, int* count);
	float* CalcRaycastTO(TempObstaclesNavMesh* toNavMesh, float sposX, float sposY, float sposZ, float eposX, float eposY, float eposZ, int* count);

	// 增加圆柱体阻挡
	void AddCylinderTO(TempObstaclesNavMesh* toNavMesh, char* tag, float posX, float posY, float posZ, float radius, float height);
	// 增加obb的box
	void AddObbBox(TempObstaclesNavMesh* toNavMesh, char* tag, float centX, float centY, float centZ, float halfX, float halfY, float halfZ, float rotaY);
	// 新增AABB的Box
	void AddAabbBox(TempObstaclesNavMesh* toNavMesh, char* tag, float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
	void RemoveTOByTag(TempObstaclesNavMesh* toNavMesh, char* tag);
	void RemoveAllTO(TempObstaclesNavMesh* toNavMesh);
	void Update(TempObstaclesNavMesh* toNavMesh);
	// 释放地图
	void FreeToNavMesh(TempObstaclesNavMesh* toNavMesh);

#pragma region 新的动态Mesh
	typedef struct ObsNavMesh ObsNavMesh;
	typedef struct ObsPathFinder ObsPathFinder;
	/*
不想使用C++管理Mesh与Finder
带Key表示放到了Map里
创建一个新的Finder
*/
	ObsNavMesh* NewObsNavMesh(char* filepath, char* key);
	/*
	不想使用C++管理Mesh与Finder
	创建一个新的Finder
	*/
	ObsPathFinder* NewObsPathFinder(ObsNavMesh* mesh);
	//获取Mesh
	// filepath 文件路径必须有
	// key 缓存起来的key，必须有
	ObsNavMesh* GetObsNavMesh(char* filepath, char* key);
	//获取Mesh对应的寻路对象
	//  filepath 文件路径
	// key 缓存起来的key
	// filepath 和key只能有一个，没有key就读一个新的Mesh，然后就通过Key要一个旧的
	ObsPathFinder* GetPathFinder(char* filepath, char* key);
	// 释放寻路对象
	void FreeObsPath(ObsPathFinder* finder);
	// 从寻路对应里获取Mesh的引用
	ObsNavMesh* GetObsNavMeshByFinder(ObsPathFinder* finder);

#pragma region 动态阻挡有关
	// 增加圆柱体阻挡
	void ObsAddCylinder(ObsNavMesh* toNavMesh, char* tag, float posX, float posY, float posZ, float radius, float height);
	// 增加OBB
	void ObsAddObbBox(ObsNavMesh* toNavMesh, char* tag, float centX, float centY, float centZ, float halfX, float halfY, float halfZ, float rotaY);
	// 增加AABB
	void ObsAddAabbBox(ObsNavMesh* toNavMesh, char* tag, float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
	// 按照名字删除掉一系列动态阻挡
	void ObsRemoveTOByTag(ObsNavMesh* toNavMesh, char* tag);
	// 移除地图中全部的动态阻挡
	void ObsRemoveAllTO(ObsNavMesh* toNavMesh);

	// 如果有动态阻挡cache，将cache生效到动态阻挡中去
	void ObsUpdate(ObsNavMesh* toNavMesh);
#pragma endregion

#pragma region 寻路有关
	// 进行一次寻路，返回路点列表
	float* ObsFindPath(ObsPathFinder* finder, float sposX, float sposY, float sposZ, float eposX, float eposY, float eposZ, int* count);

	// 查询某个点在mesh里面附近的点
	float* ObsCalcNear(ObsPathFinder* finder, float sposX, float sposY, float sposZ, int* count);

	// 射线检测一次，如果之间遇到障碍无法穿过，将会把点返回回去
	float* ObsCalcRaycast(ObsPathFinder* finder, float sposX, float sposY, float sposZ, float eposX, float eposY, float eposZ, int* count);
#pragma endregion
#pragma endregion




#ifdef __cplusplus
}
#endif

#endif // BridgeCpp_h__
